// 评论模块
const express  = require('express')
const router = express.Router()

const multer = require('multer')
const path = require('path')
const fs = require('fs')

const {
	query
} = require('../../db/conn.js')


// 加载评论列表
router.get('/list',(req,res)=>{
	// 去查询banner列表
	 let sql = "select * from (store_liuyan as l inner join store_good as g on l.good_id = g.id) inner join store_user as u on l.u_id = u.u_id"
     query(sql).then(result=>{
        let img = []
        for (var i = 0; i < result.length; i++) {
         let imgs = JSON.parse(result[i].good_pic)
         img.push(imgs[0])
        }
        res.render('liuyan/liuyan',{result,img})
     })
})

//删除评论接口
router.get('/delete',(req,res)=>{
	let {id} = req.query
	/*根据id查询该管理员的具体信息*/
	let sql_delete = "delete from store_liuyan where l_id = ?"
	query(sql_delete,[id]).then(result=>{
	   if(result){
	 		res.send('<script>alert("删除成功");location.href="/admin/liuyan/list"</script>')
	 	}
	})
})


module.exports = router